package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.SortBean;
import com.czl.module_storehouse.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xubin
 */
public class ReceiveChangeAdapter extends BaseNumAdapter<SortBean> {

    private List<SortBean> removeSorts = new ArrayList<>();

    public ReceiveChangeAdapter(int layoutResId, @Nullable List<SortBean> data) {
        super(layoutResId, data);
    }

    public List<SortBean> getRemoveSorts() {
        return removeSorts;
    }

    public void setRemoveSorts(List<SortBean> removeSorts) {
        this.removeSorts = removeSorts;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SortBean item) {
        if (item.getApplyNum() == null) {
            item.setCount(0);
        } else {
            item.setCount(item.getApplyNum());
        }
        super.convert(helper, item);
        helper.setText(R.id.tv_name, item.getSortName())
                .setText(R.id.tv_model, "型号：" + item.getSortModel());
        helper.getView(R.id.iv_delete)
                .setOnClickListener(v -> {
                    if (item.changeSort()) {
                        removeSorts.add(item);
                    }
                    remove(item);
                });
    }

    @Override
    public int getMaxCount(SortBean item) {
        return Math.min(maxCount - item.getApplyTotalNum(getData()), item.stockNum());
    }

    @Override
    public int getMinCount(SortBean item) {
        return 0;
    }

    @Override
    protected void setAfterTextChanged(BaseViewHolder helper, SortBean bean, int count) {
        bean.setApplyNum(count);
    }
}
